package com.itheima.health.controller.mobile;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.dto.SmsLoginDTO;
import com.itheima.health.pojo.dto.SubmitDTO;
import com.itheima.health.pojo.entity.Order;
import com.itheima.health.pojo.result.Result;
import com.itheima.health.pojo.vo.OrderInfoVO;
import com.itheima.health.service.MobileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobile")
@Slf4j
public class MobileController {
    @Autowired
    private MobileService mobileService;


    /**
     * 发送验证码
     * @param type
     * @param telephone
     * @return
     */
    @PostMapping("/validateCode/send")
    public Result getValidateCode(String type ,String telephone){
        log.info("验证码类型：{},手机号：{}",type,telephone);
        mobileService.getValidateCode(type,telephone);
        return new Result(true, MessageConst.SEND_VALIDATECODE_SUCCESS);
    }


    /**
     * 用户登录
     * @param dto
     * @return
     */
    @PostMapping("/login/smsLogin")
    public Result smsLogin(@RequestBody SmsLoginDTO dto){
        log.info("用户登录{}",dto);
        if(mobileService.smsLogin(dto)){
            return new Result(true,MessageConst.LOGIN_SUCCESS);
        }else {
            return new Result(false,MessageConst.LOGIN_FAIL);
        }
    }


    /**
     * 提交预约
     * @param submitDTO
     * @return
     */
    @PostMapping("/order/submit")
    public Result submit(@RequestBody SubmitDTO submitDTO){
        Order order = mobileService.submit(submitDTO);
        return new Result(true, MessageConst.ORDER_SUCCESS,order);
    }


    /**
     * 预约成功后显示信息
     * @param id
     * @return
     */
    @GetMapping("/order/findById")
    public Result findOrderById(Integer id){
        OrderInfoVO vo = mobileService.findOrderById(id);
        return new Result(true,MessageConst.QUERY_ORDER_SUCCESS,vo);
    }



}
